package com.vlong.town.controller.server.insurance;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.insurance.InsuranceInfo;
import com.vlong.town.service.insurance.InsuranceInfoService;

@RestController
@RequestMapping("/rest/insurance")
public class InsuranceRestController extends BaseController{

	@Autowired
	private  InsuranceInfoService  insuranceInfoService;//保险业务接口
	
	
	/**
     * 查询保险信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<HouseInfo>
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public List<InsuranceInfo> list(
            @PathVariable(required=true, value="pageNo") Integer pageNo,
            @PathVariable(required=true, value="pageSize") Integer pageSize) {
        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
        PageHelper.orderBy("update_time DESC");
        List<InsuranceInfo> queryList = insuranceInfoService.queryList(null, null, null, null);
        return queryList;
    }
    
    /**
     * 小程序
     * 查询保险信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<HouseInfo>
     */
    @GetMapping("/listXcx")
    public List<InsuranceInfo> listXcx() {
        List<InsuranceInfo> queryList = insuranceInfoService.queryList(null, null, null, null);
        for (InsuranceInfo insuranceInfo : queryList) {
        	Long createTime = insuranceInfo.getCreateTime();
        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
        	Date date = new  Date(createTime);
        	String format = sdf.format(date);
        	insuranceInfo.setCreateDate(format);
		}
        return queryList;
    }
    
    
    /**
     * 查询保险详情
     * @param id 保险id
     * @return InsuranceInfo
     */
    @GetMapping("/detail/{id}")
    public InsuranceInfo detail(@PathVariable(required=true, value="id") Long id) {
    	return insuranceInfoService.queryById(id);
    }
    
}
